package cn.edu.zjgsu.ito.service.impl;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.zjgsu.ito.dao.AdminInfomationMapper;
import cn.edu.zjgsu.ito.dao.AdminLoginMapper;
import cn.edu.zjgsu.ito.dao.AdminVoMapper;
import cn.edu.zjgsu.ito.dao.ComplainMapper;
import cn.edu.zjgsu.ito.dao.ComplainViewMapper;
import cn.edu.zjgsu.ito.dao.CourierOrderMapper;
import cn.edu.zjgsu.ito.dao.CourierVoMapper;
import cn.edu.zjgsu.ito.dao.DemandOrderMapper;
import cn.edu.zjgsu.ito.dao.OrderDetailInfomationViewMapper;
import cn.edu.zjgsu.ito.dao.OrderTableMapper;
import cn.edu.zjgsu.ito.dao.PurchaseOrderMapper;
import cn.edu.zjgsu.ito.dao.UserCourierMapper;
import cn.edu.zjgsu.ito.dao.UserInfomationMapper;
import cn.edu.zjgsu.ito.dao.UserLoginMapper;
import cn.edu.zjgsu.ito.dao.UserOrderViewMapper;
import cn.edu.zjgsu.ito.dao.UserScoreMapper;
import cn.edu.zjgsu.ito.dao.UserVoMapper;
import cn.edu.zjgsu.ito.model.AdminInfomation;
import cn.edu.zjgsu.ito.model.AdminInfomationExample;
import cn.edu.zjgsu.ito.model.AdminLogin;
import cn.edu.zjgsu.ito.model.AdminLoginExample;
import cn.edu.zjgsu.ito.model.AdminVo;
import cn.edu.zjgsu.ito.model.AdminVoExample;
import cn.edu.zjgsu.ito.model.Complain;
import cn.edu.zjgsu.ito.model.ComplainView;
import cn.edu.zjgsu.ito.model.ComplainViewExample;
import cn.edu.zjgsu.ito.model.CourierVo;
import cn.edu.zjgsu.ito.model.CourierVoExample;
import cn.edu.zjgsu.ito.model.DemandOrderExample;
import cn.edu.zjgsu.ito.model.OrderTableExample;
import cn.edu.zjgsu.ito.model.OrderDetailInfomationView;
import cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample;
import cn.edu.zjgsu.ito.model.OrderTable;
import cn.edu.zjgsu.ito.model.OrderTableExample;
import cn.edu.zjgsu.ito.model.UserCourier;
import cn.edu.zjgsu.ito.model.UserCourierExample;
import cn.edu.zjgsu.ito.model.UserInfomation;
import cn.edu.zjgsu.ito.model.UserInfomationExample;
import cn.edu.zjgsu.ito.model.UserLogin;
import cn.edu.zjgsu.ito.model.UserOrderViewExample;
import cn.edu.zjgsu.ito.model.UserOrderViewExample.Criteria;
import cn.edu.zjgsu.ito.model.UserScore;
import cn.edu.zjgsu.ito.model.UserVo;
import cn.edu.zjgsu.ito.model.UserVoExample;
import cn.edu.zjgsu.ito.service.IAdminService;
import cn.edu.zjgsu.ito.vo.CapitalVo;
import cn.edu.zjgsu.ito.vo.OrderDetailInfomationVo;
import cn.edu.zjgsu.ito.vo.OrderStatisticalVo;
import cn.edu.zjgsu.ito.vo.Page;

@Service
@Transactional
public class AdminServiceImpl implements IAdminService
{
	@Autowired
	private AdminLoginMapper adminLoginMapper;

	@Autowired
	private AdminInfomationMapper adminInfomationMapper;

	@Autowired
	private OrderTableMapper orderTableMapper;

	@Autowired
	private AdminVoMapper adminVoMapper;

	@Autowired
	private UserInfomationMapper userInfomationMapper;

	@Autowired
	private UserCourierMapper userCourierMapper;

	@Autowired
	private UserVoMapper userVoMapper;

	@Autowired
	private DemandOrderMapper demandOrderMapper;

	@Autowired
	private PurchaseOrderMapper purchaseOrderMapper;

	@Autowired
	private CourierOrderMapper courierOrderMapper;

	@Autowired
	private CourierVoMapper courierVoMapper;

	@Autowired
	private UserOrderViewMapper userOrderViewMapper;

	@Autowired
	private OrderDetailInfomationViewMapper orderDetailInfomationViewMapper;

	@Autowired
	private UserLoginMapper userLoginMapper;

	@Autowired
	private UserScoreMapper userScoreMapper;

	@Autowired
	private ComplainViewMapper complainViewMapper;

	@Autowired
	private ComplainMapper complainMapper;

	@Override
	public Map login(String username, String passowrd)
	{
		AdminLoginExample adminLoginExample = new AdminLoginExample();
		adminLoginExample.or().andAdminNameEqualTo(username)
				.andAdminPwdEqualTo(passowrd);
		List<AdminLogin> adminLoginList = adminLoginMapper
				.selectByExample(adminLoginExample);

		Map<String, Object> result = new HashMap<String, Object>();
		switch (adminLoginList.size())
		{
		case 0:
			result.put("result", -1);
			return result;
		case 1:
			AdminInfomationExample adminInfomationExample = new AdminInfomationExample();
			adminInfomationExample.or().andAdminNameEqualTo(
					adminLoginList.get(0).getAdminName());
			AdminInfomation amdinAdminInfomation = adminInfomationMapper
					.selectByExample(adminInfomationExample).get(0);
			result.put("result", 1);
			result.put("adminInfomation", amdinAdminInfomation);
		default:
			break;
		}
		return result;
	}

	@Override
	public int addAdmin(AdminVo adminVo)
	{
		int affectedCount1 = 0;
		int affectedCount2 = 0;
		AdminInfomation adminInfomation = new AdminInfomation();
		BeanUtils.copyProperties(adminVo, adminInfomation);
		adminInfomation.setAdminId(null);
		adminInfomation.setAdminCreatetime(new java.util.Date(System
				.currentTimeMillis()));

		AdminLogin adminLogin = new AdminLogin();
		BeanUtils.copyProperties(adminVo, adminLogin);
		adminLogin.setAdminId(null);

		AdminInfomationExample adminInfomationExample = new AdminInfomationExample();
		adminInfomationExample.or().andAdminNameEqualTo(adminVo.getAdminName());

		AdminLoginExample adminLoginExample = new AdminLoginExample();
		adminLoginExample.or().andAdminNameEqualTo(adminVo.getAdminName());
		if (adminInfomationMapper.selectByExample(adminInfomationExample)
				.size() == 0
				&& adminLoginMapper.selectByExample(adminLoginExample).size() == 0)
		{
			synchronized (this)
			{
				affectedCount1 = adminInfomationMapper
						.insertSelective(adminInfomation);
				affectedCount2 = adminLoginMapper.insertSelective(adminLogin);
			}

		} else
		{
			return 0;
		}

		if (affectedCount1 == 1 && affectedCount2 == 1)
		{
			return 1;
		} else
		{
			throw new RuntimeException();
		}

	}

	@Override
	public int delAdmin(int adminId)
	{
		int affectedCount1 = 0;
		int affectedCount2 = 0;
		String adminName = adminInfomationMapper.selectByPrimaryKey(adminId)
				.getAdminName();
		if (adminName != null && adminName.length() > 0)
		{
			AdminLoginExample adminLoginExample = new AdminLoginExample();
			adminLoginExample.or().andAdminNameEqualTo(adminName);
			synchronized (this)
			{
				affectedCount1 = adminInfomationMapper
						.deleteByPrimaryKey(adminId);
				affectedCount2 = adminLoginMapper
						.deleteByExample(adminLoginExample);
			}
		}
		if (affectedCount1 == 1 && affectedCount2 == 1)
		{
			return affectedCount1;
		} else
		{
			throw new RuntimeException();
		}
	}

	@Override
	public int getTotalOrderCount()
	{
		int count = orderTableMapper.countByExample(new OrderTableExample());
		return count;
	}

	@Override
	public AdminInfomation getAdminById(int adminId)
	{
		return adminInfomationMapper.selectByPrimaryKey(adminId);
	}

	@Override
	public int resetPassowrd(int adminId, String newPassword)
	{
		String adminName = adminInfomationMapper.selectByPrimaryKey(adminId)
				.getAdminName();
		if (adminName == null)
			return 0;
		AdminLoginExample adminLoginExample = new AdminLoginExample();
		adminLoginExample.or().andAdminNameEqualTo(adminName);
		AdminLogin adminLogin = new AdminLogin();
		adminLogin.setAdminPwd(newPassword);
		int resultCount = adminLoginMapper.updateByExampleSelective(adminLogin,
				adminLoginExample);
		if (resultCount > 1)
			throw new RuntimeException();
		else
		{
			return resultCount;
		}

	}

	@Override
	public int updateAdminWithoutPassword(AdminInfomation adminInfomation)
	{
		AdminLogin adminLogin = new AdminLogin();
		/*
		 * adminLogin.setAdminId(getIdfromInfomationToLogin(adminInfomation
		 * .getAdminId()));
		 */
		adminLogin.setAdminId(adminInfomation.getAdminId());
		adminLogin.setAdminName(adminInfomation.getAdminName());
		int resultCount = 0;
		synchronized (this)
		{
			resultCount = adminInfomationMapper
					.updateByPrimaryKeySelective(adminInfomation);
			adminLoginMapper.updateByPrimaryKeySelective(adminLogin);
		}
		return resultCount;
	}

	@Override
	public int updateAdminItself(AdminVo adminVo)
	{
		int adminId = getIdfromInfomationToLogin(adminVo.getAdminId());
		if (adminLoginMapper.selectByPrimaryKey(adminId).getAdminPwd() != adminVo
				.getOldPassword())
		{
			return 0;
		}
		AdminInfomation adminInfomation = new AdminInfomation();
		BeanUtils.copyProperties(adminVo, adminInfomation);
		AdminLogin adminLogin = new AdminLogin();
		adminLogin.setAdminId(adminId);
		adminLogin.setAdminName(adminVo.getAdminName());
		adminLogin.setAdminPwd(adminVo.getNewPassword());

		synchronized (this)
		{
			adminInfomationMapper.updateByPrimaryKeySelective(adminInfomation);
			adminLoginMapper.updateByPrimaryKeySelective(adminLogin);
		}
		return 1;
	}

	private List<? extends Object> change(List<? extends Object> list,
			int pageCount, int pageSize)
	{
		List newList = new ArrayList<>();
		for (int i = (pageCount - 1) * pageSize; i < Math.min(pageCount
				* pageSize, list.size()); i++)
		{
			newList.add(list.get(i));
		}
		return newList;
	}

	@Override
	public int checkAdminName(String adminName)
	{
		AdminInfomationExample adminInfomationExample = new AdminInfomationExample();
		adminInfomationExample.or().andAdminNameEqualTo(adminName);
		int resultCount = adminInfomationMapper.selectByExample(
				adminInfomationExample).size();
		if (resultCount > 0)
		{
			return 1;
		}
		return 0;
	}

	@Override
	public int getTotalUserCount()
	{
		return userInfomationMapper.countByExample(new UserInfomationExample());
	}

	@Override
	public int getTotalCourierCount()
	{
		return userCourierMapper.countByExample(new UserCourierExample());

	}

	@Override
	/*
	 * public List<UserVo> getUsersWithPaging(int pageCount, int pageSize, int
	 * sequence, String keyword) { UserVoExample userVoExample = new
	 * UserVoExample(); switch (sequence) { case 1: // 最新排前面
	 * userVoExample.setOrderByClause("last_login_time DESC"); break; case 2:
	 * userVoExample.setOrderByClause("last_login_time"); break; default: break;
	 * }
	 * 
	 * if (keyword != null && keyword.length() > 0) {
	 * userVoExample.or().andUsernameLike("%" + keyword + "%"); } List<UserVo>
	 * userVoAll = userVoMapper.selectByExample(userVoExample); List<UserVo>
	 * userVos = new ArrayList<UserVo>(); for (int i = (pageCount - 1) *
	 * pageSize; i < Math.min(pageCount pageSize, userVoAll.size()); i++) {
	 * userVos.add(userVoAll.get(i)); } return userVos; }
	 */
	public Page<UserVo> getUsersWithPaging(int pageCount, int pageSize,
			int sequence, String keyword)
	{
		Page<UserVo> page = new Page<UserVo>();
		UserVoExample userVoExample = new UserVoExample();
		userVoExample.setStart(Math.max(0, (pageCount - 1) * pageSize));
		switch (sequence)
		{
		case 1:
			// 最新排前面
			userVoExample.setOrderByClause("last_login_time DESC");
			break;
		case 2:
			userVoExample.setOrderByClause("last_login_time");
			break;
		case 3:
			// 最新排前面
			userVoExample.setOrderByClause("credit_score");
			break;
		case 4:
			userVoExample.setOrderByClause("credit_score DESC");
			break;
		case 5:
			// 最新排前面
			userVoExample.setOrderByClause("user_register_time");
			break;
		case 6:
			userVoExample.setOrderByClause("user_register_time DESC");
			break;
		default:
			break;
		}

		if (keyword != null && keyword.length() > 0)
		{
			userVoExample.or().andUsernameLike("%" + keyword + "%");
		}
		/*
		 * List<UserVo> userVoAll = userVoMapper.selectByExample(userVoExample);
		 * List<UserVo> userVos = new ArrayList<UserVo>(); for (int i =
		 * (pageCount - 1) * pageSize; i < Math.min(pageCount pageSize,
		 * userVoAll.size()); i++) { userVos.add(userVoAll.get(i)); }
		 */
		page.setData(userVoMapper.selectByExample(userVoExample));
		page.setTotalCount(userVoMapper.countByExample(userVoExample));
		page.setPageCount(pageCount);
		page.setPageSize(pageSize);
		return page;
	}

	@Override
	public UserVo getUserByUserId(int userId)
	{
		UserVoExample userVoExample = new UserVoExample();
		userVoExample.or().andUserIdEqualTo(userId);
		return userVoMapper.selectByExample(userVoExample).get(0);
	}

	/*
	 * public List<AdminVo> getAdminsWithPaging(int pageCount, int pageSize, int
	 * sequence, String keyword) { AdminVoExample adminVoExample = new
	 * AdminVoExample(); cn.edu.zjgsu.ito.model.AdminVoExample.Criteria criteria
	 * = adminVoExample .or(); adminVoExample.setOrderByClause("admin_name");
	 * criteria.andAdminNameLike("%" + keyword == null ? "" : keyword + "%");
	 * switch (sequence) { case 1: break; case 2:
	 * criteria.andAdminPowerEqualTo(1); break; case 3:
	 * criteria.andAdminPowerEqualTo(0); break; default: break; } List<AdminVo>
	 * adminInfos = adminVoMapper .selectByExample(adminVoExample);
	 * List<AdminVo> admins = new ArrayList<AdminVo>(); for (int i = (pageCount
	 * - 1) * pageSize; i < Math.min(pageSize pageCount, adminInfos.size());
	 * i++) { admins.add(adminInfos.get(i)); } return admins; }
	 */

	@Override
	/**
	 * 分页得到管理员(新)
	 */
	public Page<AdminVo> getAdminsWithPaging(int pageCount, int pageSize,
			int sequence, String keyword)
	{
		Page<AdminVo> page = new Page<AdminVo>();
		AdminVoExample adminVoExample = new AdminVoExample();
		cn.edu.zjgsu.ito.model.AdminVoExample.Criteria criteria = adminVoExample
				.or();
		adminVoExample.setOrderByClause("admin_name");
		adminVoExample.setStart(Math.max(0, (pageCount - 1) * pageSize));
		criteria.andAdminNameLike("%" + keyword == null ? "" : keyword + "%");
		switch (sequence)
		{
		case 1:
			break;
		case 2:
			criteria.andAdminPowerEqualTo(1);
			break;
		case 3:
			criteria.andAdminPowerEqualTo(0);
			break;
		default:
			break;
		}
		/*
		 * List<AdminVo> adminInfos = adminVoMapper
		 * .selectByExample(adminVoExample); List<AdminVo> admins = new
		 * ArrayList<AdminVo>(); for (int i = (pageCount - 1) * pageSize; i <
		 * Math.min(pageSize pageCount, adminInfos.size()); i++) {
		 * admins.add(adminInfos.get(i)); }
		 */
		page.setData(adminVoMapper.selectByExample(adminVoExample));
		page.setPageCount(adminVoMapper.countByExample(adminVoExample));
		page.setPageCount(pageCount);
		page.setPageSize(pageSize);
		return page;
	}

	@Override
	public int getTodayOrderCount()
	{
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		calendar.set(Calendar.MILLISECOND, 0);
		DemandOrderExample demandOrderExample = new DemandOrderExample();
		demandOrderExample.or()
				.andDemandCreatetimeLessThan(Calendar.getInstance().getTime())
				.andDemandCreatetimeGreaterThan(calendar.getTime());
		return demandOrderMapper.countByExample(demandOrderExample);
	}

	@Override
	public CourierVo getCourierByCourierId(int courierId)
	{
		CourierVoExample courierVoExample = new CourierVoExample();
		courierVoExample.or().andCourierIdEqualTo(courierId);
		return courierVoMapper.selectByExample(courierVoExample).get(0);
	}

	@Override
	public int closeAdmin(int adminId, int adminState)
	{
		int adminLoginId = getIdfromInfomationToLogin(adminId);
		AdminLogin adminLogin = new AdminLogin();
		adminLogin.setAdminId(adminId);
		adminLogin.setAdminState(adminState);
		int resultCount = adminLoginMapper
				.updateByPrimaryKeySelective(adminLogin);
		if (resultCount != 1)
		{
			throw new RuntimeException();
		}
		return resultCount;
	}

	@Override
	public int openAdmin(int adminId, int adminState)
	{
		int adminLoginId = getIdfromInfomationToLogin(adminId);
		AdminLogin adminLogin = new AdminLogin();
		adminLogin.setAdminId(adminId);
		adminLogin.setAdminState(adminState);
		int resultCount = adminLoginMapper
				.updateByPrimaryKeySelective(adminLogin);
		if (resultCount != 1)
		{
			throw new RuntimeException();
		}
		return resultCount;
	}

	/*
	 * public List<CourierVo> getCouriersWithPaging(int pageCount, int pageSize,
	 * int sequence, String keyword) { CourierVoExample courierVoExample = new
	 * CourierVoExample(); cn.edu.zjgsu.ito.model.CourierVoExample.Criteria
	 * criteria = courierVoExample.or(); if(keyword!=null&&keyword.length()>0) {
	 * criteria.andUsernameLike("%"+keyword+"%"); } switch (sequence) { case 1:
	 * courierVoExample.setOrderByClause("sum_order"); break; case 2:
	 * courierVoExample.setOrderByClause("sum_order DESC"); break; case 3:
	 * courierVoExample.setOrderByClause("score"); break; case 4:
	 * courierVoExample.setOrderByClause("score DESC"); break; case 5:
	 * courierVoExample.setOrderByClause("create_time DESC"); break; case 6:
	 * courierVoExample.setOrderByClause("create_time"); break; default: break;
	 * } List<CourierVo> courierVos =
	 * courierVoMapper.selectByExample(courierVoExample); List<CourierVo>
	 * resultList = new ArrayList<CourierVo>(); for(int
	 * i=(pageCount-1)*pageSize;i<Math.min((pageCount*pageSize),
	 * courierVos.size());i++) { resultList.add(courierVos.get(i)); } return
	 * resultList; }
	 */

	public Page<CourierVo> getCouriersWithPaging(int pageCount, int pageSize,
			int sequence, String keyword)
	{
		Page<CourierVo> page = new Page<CourierVo>();
		CourierVoExample courierVoExample = new CourierVoExample();
		cn.edu.zjgsu.ito.model.CourierVoExample.Criteria criteria = courierVoExample
				.or();
		if (keyword != null && keyword.length() > 0)
		{
			criteria.andUsernameLike("%" + keyword + "%");
		}
		switch (sequence)
		{
		case 1:
			courierVoExample.setOrderByClause("sum_order");
			break;
		case 2:
			courierVoExample.setOrderByClause("sum_order DESC");
			break;
		case 3:
			courierVoExample.setOrderByClause("score");
			break;
		case 4:
			courierVoExample.setOrderByClause("score DESC");
			break;
		case 5:
			courierVoExample.setOrderByClause("create_time DESC");
			break;
		case 6:
			courierVoExample.setOrderByClause("create_time");
			break;
		default:
			break;
		}
		/*
		 * List<CourierVo> courierVos =
		 * courierVoMapper.selectByExample(courierVoExample); List<CourierVo>
		 * resultList = new ArrayList<CourierVo>(); for(int
		 * i=(pageCount-1)*pageSize;i<Math.min((pageCount*pageSize),
		 * courierVos.size());i++) { resultList.add(courierVos.get(i)); }
		 */
		page.setData(courierVoMapper.selectByExample(courierVoExample));
		page.setTotalCount(courierVoMapper.countByExample(courierVoExample));
		page.setPageCount(pageCount);
		page.setPageSize(pageSize);
		return page;
	}

	/*
	 * public List<OrderStatisticalVo> getOrderByCourierId(int courierId, int
	 * sequence, String key, int pageCount, int pageSize) { return
	 * paginator(getAllOrdersByCourierId(courierId, sequence, key, pageCount,
	 * pageSize), pageCount, pageSize); }
	 */

	@Override
	public Page<OrderDetailInfomationView> getOrderByCourierId(int courierId,
			int sequence, String keyword, int pageCount, int pageSize)
	{

		Page<OrderDetailInfomationView> page = new Page<OrderDetailInfomationView>();
		OrderDetailInfomationViewExample orderDetailInfomationViewExample = new OrderDetailInfomationViewExample();
		/*
		 * orderDetailInfomationViewExample.setStart(Math.max(0, (pageCount - 1)
		 * pageSize)); orderDetailInfomationViewExample.setPageSize(pageSize);
		 */

		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria = orderDetailInfomationViewExample
				.or();
		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria2 = orderDetailInfomationViewExample
				.or();
		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria3 = orderDetailInfomationViewExample
				.or();
		if (keyword != null && keyword.length() > 0)
		{
			criteria.andNicknameLike("%" + keyword + "%");
			criteria2.andPurchaseUserNicknameLike("%" + keyword + "%");
			criteria3.andCourierNicknameLike("%" + keyword + "%");
		}
		criteria.andCourierIdEqualTo(courierId);
		criteria2.andCourierIdEqualTo(courierId);
		criteria3.andCourierIdEqualTo(courierId);

		if (sequence != -1)
		{
			criteria.andOrderStateEqualTo(sequence);
			criteria2.andOrderStateEqualTo(sequence);
			criteria3.andOrderStateEqualTo(sequence);
		}

		List<OrderDetailInfomationView> orderDetailInfomationViews = orderDetailInfomationViewMapper
				.selectByExample(orderDetailInfomationViewExample);

		page.setData(orderDetailInfomationViews);
		page.setPageCount(pageCount);
		page.setPageSize(pageSize);
		page.setTotalCount(orderDetailInfomationViewMapper
				.countByExample(orderDetailInfomationViewExample));
		return page;

		/*
		 * Page<OrderStatisticalVo> page = new Page<OrderStatisticalVo>();
		 * 
		 * UserOrderViewExample userOrderViewExample = new
		 * UserOrderViewExample(); userOrderViewExample.setStart(Math.max(0,
		 * (pageCount - 1) * pageSize));
		 * userOrderViewExample.setPageSize(pageSize); Criteria criteria =
		 * userOrderViewExample.or(); if (keyword != null && keyword.length() >
		 * 0) { criteria.andNicknameLike("%" + keyword + "%"); }
		 * criteria.andCourierIdEqualTo(courierId); List<UserOrderView>
		 * userOrderViews = userOrderViewMapper
		 * .selectByExample(userOrderViewExample);
		 * 
		 * List<OrderStatisticalVo> orderStatisticalVos = new
		 * ArrayList<OrderStatisticalVo>(); OrderStatisticalVo
		 * orderStatisticalVo; UserInfomation userInfomation; for (int i = 0; i
		 * < userOrderViews.size(); i++) { orderStatisticalVo = new
		 * OrderStatisticalVo(); orderStatisticalVo.setType(1);
		 * BeanUtils.copyProperties(userOrderViews.get(i), orderStatisticalVo);
		 * 
		 * userInfomation = userInfomationMapper
		 * .selectByPrimaryKey(userOrderViews.get(i) .getPurchaseUserId()); if
		 * (userInfomation != null) { orderStatisticalVo
		 * .setPurchaseUserheadPortraitUrl(checkString(userInfomation
		 * .getHeadPortraitUrl())); orderStatisticalVo
		 * .setPurchaseUserNickname(checkString(userInfomation .getNickname()));
		 * } orderStatisticalVos.add(orderStatisticalVo); }
		 * 
		 * page.setData(orderStatisticalVos);
		 * page.setTotalCount(userOrderViewMapper
		 * .countByExample(userOrderViewExample)); page.setPageCount(pageCount);
		 * page.setPageSize(pageSize);
		 * 
		 * return page;
		 */
	}

	/*
	 * @Override public List<OrderStatisticalVo> getDemandOrderByUserId(int
	 * userId, int sequence, String keyword, int pageCount, int pageSize) {
	 * return paginator(getDemandOrderByUser(userId, sequence, keyword),
	 * pageCount, pageSize); }
	 */

	/*
	 * @Override
	 *//**
	 * 得到用户请求订单
	 */
	/*
	 * public Page<OrderStatisticalVo> getDemandOrderByUserId(int userId, int
	 * sequence, String keyword, int pageCount, int pageSize) {
	 * Page<OrderStatisticalVo> page = new Page<OrderStatisticalVo>();
	 * 
	 * UserOrderViewExample userOrderViewExample = new UserOrderViewExample();
	 * userOrderViewExample.setStart(Math.max(0, (pageCount - 1) * pageSize));
	 * userOrderViewExample.setPageSize(pageSize); Criteria criteria =
	 * userOrderViewExample.or(); if (keyword != null && keyword.length() > 0) {
	 * criteria.andNicknameLike("%" + keyword + "%"); }
	 * criteria.andUserIdEqualTo(userId); List<UserOrderView> userOrderViews =
	 * userOrderViewMapper .selectByExample(userOrderViewExample);
	 * 
	 * List<OrderStatisticalVo> orderStatisticalVos = new
	 * ArrayList<OrderStatisticalVo>(); OrderStatisticalVo orderStatisticalVo;
	 * UserInfomation userInfomation; for (int i = 0; i < userOrderViews.size();
	 * i++) { orderStatisticalVo = new OrderStatisticalVo();
	 * orderStatisticalVo.setType(1);
	 * BeanUtils.copyProperties(userOrderViews.get(i), orderStatisticalVo);
	 * 
	 * userInfomation = userInfomationMapper
	 * .selectByPrimaryKey(userOrderViews.get(i) .getPurchaseUserId()); if
	 * (userInfomation != null) { orderStatisticalVo
	 * .setPurchaseUserheadPortraitUrl(checkString(userInfomation
	 * .getHeadPortraitUrl())); orderStatisticalVo
	 * .setPurchaseUserNickname(checkString(userInfomation .getNickname())); }
	 * orderStatisticalVos.add(orderStatisticalVo); }
	 * 
	 * page.setData(orderStatisticalVos); page.setTotalCount(userOrderViewMapper
	 * .countByExample(userOrderViewExample)); page.setPageCount(pageCount);
	 * page.setPageSize(pageSize); return page; }
	 */

	@Override
	/**
	 * 得到用户请求订单
	 */
	public Page<OrderDetailInfomationView> getDemandOrderByUserId(int userId,
			int sequence, String keyword, int pageCount, int pageSize)
	{
		Page<OrderDetailInfomationView> page = new Page<OrderDetailInfomationView>();
		OrderDetailInfomationViewExample orderDetailInfomationViewExample = new OrderDetailInfomationViewExample();
		/*
		 * orderDetailInfomationViewExample.setStart(Math.max(0, (pageCount - 1)
		 * pageSize)); orderDetailInfomationViewExample.setPageSize(pageSize);
		 */

		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria = orderDetailInfomationViewExample
				.or();
		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria2 = orderDetailInfomationViewExample
				.or();
		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria3 = orderDetailInfomationViewExample
				.or();

		/**
		 * 订单状态 0-等待代购人确定金额 1-确认，未支付 2-已支付 3-找快递员 4-待取件 5-派送中 6-完成 7-关闭 8-退款中
		 */

		if (keyword != null && keyword.length() > 0)
		{
			criteria.andNicknameLike("%" + keyword + "%");
			criteria2.andPurchaseUserNicknameLike("%" + keyword + "%");
			criteria3.andCourierNicknameLike("%" + keyword + "%");
		}
		criteria.andUserIdEqualTo(userId);
		criteria2.andUserIdEqualTo(userId);
		criteria3.andUserIdEqualTo(userId);

		if (sequence != -1)
		{
			criteria.andOrderStateEqualTo(sequence);
			criteria2.andOrderStateEqualTo(sequence);
			criteria3.andOrderStateEqualTo(sequence);
		}

		List<OrderDetailInfomationView> orderDetailInfomationViews = orderDetailInfomationViewMapper
				.selectByExample(orderDetailInfomationViewExample);

		for (int i = 0; i < orderDetailInfomationViews.size(); i++)
		{
			orderDetailInfomationViews.get(i).setType(1);
		}
		page.setData(orderDetailInfomationViews);
		page.setPageCount(pageCount);
		page.setPageSize(pageSize);
		page.setTotalCount(orderDetailInfomationViewMapper
				.countByExample(orderDetailInfomationViewExample));
		return page;
	}

	/*
	 * @Override public List<OrderStatisticalVo> getPurcaseOrderByUserId(int
	 * userId, int sequence, String keyword, int pageCount, int pageSize) {
	 * return paginator(getPurchaseOrderByUser(userId, sequence, keyword),
	 * pageCount, pageSize); }
	 */

	@Override
	public Page<OrderDetailInfomationView> getPurcaseOrderByUserId(int userId,
			int sequence, String keyword, int pageCount, int pageSize)
	{

		Page<OrderDetailInfomationView> page = new Page<OrderDetailInfomationView>();
		OrderDetailInfomationViewExample orderDetailInfomationViewExample = new OrderDetailInfomationViewExample();
		orderDetailInfomationViewExample.setStart(Math.max(0, (pageCount - 1)
				* pageSize));
		orderDetailInfomationViewExample.setPageSize(pageSize);

		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria = orderDetailInfomationViewExample
				.or();
		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria2 = orderDetailInfomationViewExample
				.or();
		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria3 = orderDetailInfomationViewExample
				.or();
		if (keyword != null && keyword.length() > 0)
		{
			criteria.andNicknameLike("%" + keyword + "%");
			criteria2.andPurchaseUserNicknameLike("%" + keyword + "%");
			criteria3.andCourierNicknameLike("%" + keyword + "%");
		}
		criteria.andPurchaseUserIdEqualTo(userId);
		criteria2.andPurchaseUserIdEqualTo(userId);
		criteria3.andPurchaseUserIdEqualTo(userId);

		if (sequence != -1)
		{
			criteria.andOrderStateEqualTo(sequence);
			criteria2.andOrderStateEqualTo(sequence);
			criteria3.andOrderStateEqualTo(sequence);
		}

		List<OrderDetailInfomationView> orderDetailInfomationViews = orderDetailInfomationViewMapper
				.selectByExample(orderDetailInfomationViewExample);

		for (int i = 0; i < orderDetailInfomationViews.size(); i++)
		{
			orderDetailInfomationViews.get(i).setType(2);
		}
		page.setData(orderDetailInfomationViews);
		page.setPageCount(pageCount);
		page.setPageSize(pageSize);
		page.setTotalCount(orderDetailInfomationViewMapper
				.countByExample(orderDetailInfomationViewExample));
		return page;
	}

	/*
	 * Page<OrderStatisticalVo> page = new Page<OrderStatisticalVo>();
	 * UserOrderViewExample userOrderViewExample = new UserOrderViewExample();
	 * Criteria criteria = userOrderViewExample.or();
	 * userOrderViewExample.setStart(Math.max(0, (pageCount - 1) * pageSize));
	 * userOrderViewExample.setPageSize(pageSize); if (keyword != null &&
	 * keyword.length() > 0) { criteria.andNicknameLike("%" + keyword + "%"); }
	 * criteria.andPurchaseUserIdEqualTo(userId); List<UserOrderView>
	 * userOrderViews = userOrderViewMapper
	 * .selectByExample(userOrderViewExample);
	 * 
	 * List<OrderStatisticalVo> orderStatisticalVos = new
	 * ArrayList<OrderStatisticalVo>(); OrderStatisticalVo orderStatisticalVo;
	 * UserInfomation userInfomation; for (int i = 0; i < userOrderViews.size();
	 * i++) { orderStatisticalVo = new OrderStatisticalVo();
	 * orderStatisticalVo.setType(2);
	 * BeanUtils.copyProperties(userOrderViews.get(i), orderStatisticalVo);
	 * 
	 * userInfomation = userInfomationMapper
	 * .selectByPrimaryKey(userOrderViews.get(i) .getPurchaseUserId()); if
	 * (userInfomation != null) { orderStatisticalVo
	 * .setPurchaseUserheadPortraitUrl(checkString(userInfomation
	 * .getHeadPortraitUrl())); orderStatisticalVo
	 * .setPurchaseUserNickname(checkString(userInfomation .getNickname())); }
	 * orderStatisticalVos.add(orderStatisticalVo); }
	 * page.setData(orderStatisticalVos); page.setTotalCount(userOrderViewMapper
	 * .countByExample(userOrderViewExample)); page.setPageSize(pageSize);
	 * page.setPageCount(pageCount); return page;
	 */

	/*
	 * @Override public List<OrderStatisticalVo> getAllOrderByUserId(int userId,
	 * int sequence, String keyword, int pageCount, int pageSize) {
	 * List<OrderStatisticalVo> orderStatisticalVos = new
	 * ArrayList<OrderStatisticalVo>();
	 * orderStatisticalVos.addAll(getDemandOrderByUser(userId, sequence,
	 * keyword)); orderStatisticalVos.addAll(getPurchaseOrderByUser(userId,
	 * sequence, keyword)); return paginator(orderStatisticalVos, pageCount,
	 * pageSize); }
	 */

	@Override
	public Page<OrderDetailInfomationView> getAllOrderByUserId(int userId,
			int sequence, String keyword, int pageCount, int pageSize)
	{
		Page<OrderDetailInfomationView> page = new Page<OrderDetailInfomationView>();
		OrderDetailInfomationViewExample orderDetailInfomationViewExample = new OrderDetailInfomationViewExample();
		orderDetailInfomationViewExample.setStart(Math.max(0, (pageCount - 1)
				* pageSize));
		orderDetailInfomationViewExample.setPageSize(pageSize);

		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria = orderDetailInfomationViewExample
				.or();
		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria2 = orderDetailInfomationViewExample
				.or();
		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria3 = orderDetailInfomationViewExample
				.or();
		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria4 = orderDetailInfomationViewExample
				.or();
		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria5 = orderDetailInfomationViewExample
				.or();
		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria6 = orderDetailInfomationViewExample
				.or();
		if (keyword != null && keyword.length() > 0)
		{
			criteria.andNicknameLike("%" + keyword + "%");
			criteria2.andNicknameLike("%" + keyword + "%");
			criteria3.andPurchaseUserNicknameLike("%" + keyword + "%");
			criteria4.andPurchaseUserNicknameLike("%" + keyword + "%");
			criteria5.andCourierNicknameLike("%" + keyword + "%");
			criteria6.andCourierNicknameLike("%" + keyword + "%");
		}
		criteria.andUserIdEqualTo(userId);
		criteria2.andPurchaseUserIdEqualTo(userId);
		criteria3.andUserIdEqualTo(userId);
		criteria4.andPurchaseUserIdEqualTo(userId);
		criteria5.andUserIdEqualTo(userId);
		criteria6.andPurchaseUserIdEqualTo(userId);

		if (sequence != -1)
		{
			criteria.andOrderStateEqualTo(sequence);
			criteria2.andOrderStateEqualTo(sequence);
			criteria3.andOrderStateEqualTo(sequence);
			criteria4.andOrderStateEqualTo(sequence);
			criteria5.andOrderStateEqualTo(sequence);
			criteria6.andOrderStateEqualTo(sequence);
		}

		List<OrderDetailInfomationView> orderDetailInfomationViews = orderDetailInfomationViewMapper
				.selectByExample(orderDetailInfomationViewExample);

		for (int i = 0; i < orderDetailInfomationViews.size(); i++)
		{
			if (orderDetailInfomationViews.get(i).getUserId() == userId)
			{
				orderDetailInfomationViews.get(i).setType(1);
			} else if (orderDetailInfomationViews.get(i).getPurchaseUserId() == userId)
			{
				orderDetailInfomationViews.get(i).setType(2);
			}
		}
		page.setData(orderDetailInfomationViews);
		page.setPageCount(pageCount);
		page.setPageSize(pageSize);
		page.setTotalCount(orderDetailInfomationViewMapper
				.countByExample(orderDetailInfomationViewExample));
		return page;

		/*
		 * Page<OrderStatisticalVo> page = new Page<OrderStatisticalVo>();
		 * 
		 * UserOrderViewExample userOrderViewExample = new
		 * UserOrderViewExample(); userOrderViewExample.setStart(Math.max(0,
		 * (pageCount - 1) * pageSize));
		 * userOrderViewExample.setPageSize(pageSize); Criteria criteria =
		 * userOrderViewExample.or(); Criteria criteria2 =
		 * userOrderViewExample.or(); if (keyword != null && keyword.length() >
		 * 0) { criteria.andNicknameLike("%" + keyword + "%");
		 * criteria2.andNicknameLike("%" + keyword + "%"); }
		 * criteria.andUserIdEqualTo(userId);
		 * criteria2.andPurchaseUserIdEqualTo(userId); List<UserOrderView>
		 * userOrderViews = userOrderViewMapper
		 * .selectByExample(userOrderViewExample);
		 * 
		 * List<OrderStatisticalVo> orderStatisticalVos = new
		 * ArrayList<OrderStatisticalVo>(); OrderStatisticalVo
		 * orderStatisticalVo; UserInfomation userInfomation; for (int i = 0; i
		 * < userOrderViews.size(); i++) { orderStatisticalVo = new
		 * OrderStatisticalVo(); if (userOrderViews.get(i).getUserId() ==
		 * userId) { orderStatisticalVo.setType(1);
		 * BeanUtils.copyProperties(userOrderViews.get(i), orderStatisticalVo);
		 * userInfomation = userInfomationMapper
		 * .selectByPrimaryKey(userOrderViews.get(i) .getPurchaseUserId()); if
		 * (userInfomation != null) { orderStatisticalVo
		 * .setPurchaseUserheadPortraitUrl(checkString(userInfomation
		 * .getHeadPortraitUrl())); orderStatisticalVo
		 * .setPurchaseUserNickname(checkString(userInfomation .getNickname()));
		 * } orderStatisticalVos.add(orderStatisticalVo); } else if
		 * (userOrderViews.get(i).getPurchaseUserId() == userId) {
		 * orderStatisticalVo.setType(2);
		 * BeanUtils.copyProperties(userOrderViews.get(i), orderStatisticalVo);
		 * userInfomation = userInfomationMapper
		 * .selectByPrimaryKey(userOrderViews.get(i) .getPurchaseUserId()); if
		 * (userInfomation != null) { orderStatisticalVo
		 * .setPurchaseUserheadPortraitUrl(checkString(userInfomation
		 * .getHeadPortraitUrl())); orderStatisticalVo
		 * .setPurchaseUserNickname(checkString(userInfomation .getNickname()));
		 * } orderStatisticalVos.add(orderStatisticalVo); } }
		 * 
		 * page.setData(orderStatisticalVos);
		 * page.setTotalCount(userOrderViewMapper
		 * .countByExample(userOrderViewExample)); page.setPageCount(pageCount);
		 * page.setPageSize(pageSize); return page;
		 */
	}

	/**
	 * 得到快递员订单
	 */
	/*
	 * private List<OrderStatisticalVo> getAllOrdersByCourierId(int courierId,
	 * int sequence, String keyword, int pageCount, int pageSize) {
	 * UserOrderViewExample userOrderViewExample = new UserOrderViewExample();
	 * Criteria criteria = userOrderViewExample.or(); if (keyword != null &&
	 * keyword.length() > 0) { criteria.andNicknameLike("%" + keyword + "%"); }
	 * criteria.andCourierIdEqualTo(courierId); List<UserOrderView>
	 * userOrderViews = userOrderViewMapper
	 * .selectByExample(userOrderViewExample);
	 * 
	 * List<OrderStatisticalVo> orderStatisticalVos = new
	 * ArrayList<OrderStatisticalVo>(); OrderStatisticalVo orderStatisticalVo;
	 * UserInfomation userInfomation; for (int i = 0; i < userOrderViews.size();
	 * i++) { orderStatisticalVo = new OrderStatisticalVo();
	 * orderStatisticalVo.setType(1);
	 * BeanUtils.copyProperties(userOrderViews.get(i), orderStatisticalVo);
	 * 
	 * userInfomation = userInfomationMapper
	 * .selectByPrimaryKey(userOrderViews.get(i) .getPurchaseUserId()); if
	 * (userInfomation != null) { orderStatisticalVo
	 * .setPurchaseUserheadPortraitUrl(checkString(userInfomation
	 * .getHeadPortraitUrl())); orderStatisticalVo
	 * .setPurchaseUserNickname(checkString(userInfomation .getNickname())); }
	 * orderStatisticalVos.add(orderStatisticalVo); }
	 * 
	 * return paginator(orderStatisticalVos, pageCount, pageSize); }
	 */

	/**
	 * 得到所有订单
	 */
	@Override
	public Page<OrderDetailInfomationView> getAllOrders(int sequence,
			String keyword, int pageCount, int pageSize)
	{
		Page<OrderDetailInfomationView> page = new Page<OrderDetailInfomationView>();
		OrderDetailInfomationViewExample orderDetailInfomationViewExample = new OrderDetailInfomationViewExample();
		orderDetailInfomationViewExample.setStart(Math.max(0, (pageCount - 1)
				* pageSize));
		orderDetailInfomationViewExample.setPageSize(pageSize);

		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria = orderDetailInfomationViewExample
				.or();
		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria2 = orderDetailInfomationViewExample
				.or();
		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria3 = orderDetailInfomationViewExample
				.or();
		if (keyword != null && keyword.length() > 0)
		{
			criteria.andNicknameLike("%" + keyword + "%");
			criteria2.andPurchaseUserNicknameLike("%" + keyword + "%");
			criteria3.andCourierNicknameLike("%" + keyword + "%");
		}

		if (sequence != -1)
		{
			criteria.andOrderStateEqualTo(sequence);
			criteria2.andOrderStateEqualTo(sequence);
			criteria3.andOrderStateEqualTo(sequence);
		}

		List<OrderDetailInfomationView> orderDetailInfomationViews = orderDetailInfomationViewMapper
				.selectByExample(orderDetailInfomationViewExample);

		page.setData(orderDetailInfomationViews);
		page.setPageCount(pageCount);
		page.setPageSize(pageSize);
		page.setTotalCount(orderDetailInfomationViewMapper
				.countByExample(orderDetailInfomationViewExample));
		return page;

		/*
		 * UserOrderViewExample userOrderViewExample = new
		 * UserOrderViewExample(); Criteria criteria =
		 * userOrderViewExample.or(); if (keyword != null && keyword.length() >
		 * 0) { criteria.andNicknameLike("%" + keyword + "%"); }
		 * List<UserOrderView> userOrderViews = userOrderViewMapper
		 * .selectByExample(userOrderViewExample);
		 * 
		 * List<OrderStatisticalVo> orderStatisticalVos = new
		 * ArrayList<OrderStatisticalVo>(); OrderStatisticalVo
		 * orderStatisticalVo; UserInfomation userInfomation; for (int i = 0; i
		 * < userOrderViews.size(); i++) { orderStatisticalVo = new
		 * OrderStatisticalVo(); orderStatisticalVo.setType(1);
		 * BeanUtils.copyProperties(userOrderViews.get(i), orderStatisticalVo);
		 * 
		 * userInfomation = userInfomationMapper
		 * .selectByPrimaryKey(userOrderViews.get(i) .getPurchaseUserId()); if
		 * (userInfomation != null) { orderStatisticalVo
		 * .setPurchaseUserheadPortraitUrl(checkString(userInfomation
		 * .getHeadPortraitUrl())); orderStatisticalVo
		 * .setPurchaseUserNickname(checkString(userInfomation .getNickname()));
		 * } orderStatisticalVos.add(orderStatisticalVo); }
		 * 
		 * return paginator(orderStatisticalVos, pageCount, pageSize);
		 */

	}

	/**
	 * 得到一个用户的请求订单
	 * 
	 * @param userId
	 * @return
	 */
	/*
	 * private List<OrderStatisticalVo> getDemandOrderByUser(int userId, int
	 * sequence, String keyword) { UserOrderViewExample userOrderViewExample =
	 * new UserOrderViewExample(); Criteria criteria =
	 * userOrderViewExample.or(); if (keyword != null && keyword.length() > 0) {
	 * criteria.andNicknameLike("%" + keyword + "%"); }
	 * criteria.andUserIdEqualTo(userId); List<UserOrderView> userOrderViews =
	 * userOrderViewMapper .selectByExample(userOrderViewExample);
	 * 
	 * List<OrderStatisticalVo> orderStatisticalVos = new
	 * ArrayList<OrderStatisticalVo>(); OrderStatisticalVo orderStatisticalVo;
	 * UserInfomation userInfomation; for (int i = 0; i < userOrderViews.size();
	 * i++) { orderStatisticalVo = new OrderStatisticalVo();
	 * orderStatisticalVo.setType(1);
	 * BeanUtils.copyProperties(userOrderViews.get(i), orderStatisticalVo);
	 * 
	 * userInfomation = userInfomationMapper
	 * .selectByPrimaryKey(userOrderViews.get(i) .getPurchaseUserId()); if
	 * (userInfomation != null) { orderStatisticalVo
	 * .setPurchaseUserheadPortraitUrl(checkString(userInfomation
	 * .getHeadPortraitUrl())); orderStatisticalVo
	 * .setPurchaseUserNickname(checkString(userInfomation .getNickname())); }
	 * orderStatisticalVos.add(orderStatisticalVo); } return
	 * orderStatisticalVos; }
	 */

	/**
	 * 得到一个用户的代购订单
	 * 
	 * @param userId
	 * @return
	 */
	/*
	 * private List<OrderStatisticalVo> getPurchaseOrderByUser(int userId, int
	 * sequence, String keyword) { UserOrderViewExample userOrderViewExample =
	 * new UserOrderViewExample(); Criteria criteria =
	 * userOrderViewExample.or(); if (keyword != null && !keyword.equals("")) {
	 * criteria.andNicknameLike("%" + keyword + "%"); }
	 * userOrderViewExample.or().andPurchaseUserIdEqualTo(userId);
	 * List<UserOrderView> userOrderViews = userOrderViewMapper
	 * .selectByExample(userOrderViewExample);
	 * 
	 * List<OrderStatisticalVo> orderStatisticalVos = new
	 * ArrayList<OrderStatisticalVo>(); OrderStatisticalVo orderStatisticalVo;
	 * UserInfomation userInfomation; for (int i = 0; i < userOrderViews.size();
	 * i++) { orderStatisticalVo = new OrderStatisticalVo();
	 * orderStatisticalVo.setType(2);
	 * BeanUtils.copyProperties(userOrderViews.get(i), orderStatisticalVo);
	 * 
	 * userInfomation = userInfomationMapper
	 * .selectByPrimaryKey(userOrderViews.get(i) .getPurchaseUserId()); if
	 * (userInfomation != null) { orderStatisticalVo
	 * .setPurchaseUserheadPortraitUrl(checkString(userInfomation
	 * .getHeadPortraitUrl())); orderStatisticalVo
	 * .setPurchaseUserNickname(checkString(userInfomation .getNickname())); }
	 * orderStatisticalVos.add(orderStatisticalVo); } return
	 * orderStatisticalVos; }
	 */

	@Override
	public List<CourierVo> getCouriers(int pageCount, int pageSize,
			int sequence, String keyword)
	{
		CourierVoExample courierVoExample = new CourierVoExample();
		courierVoExample.setStartAndPageSize((pageCount - 1) * pageSize,
				pageSize);
		if (keyword != null && keyword.length() > 0)
		{
			courierVoExample.or().andReadNameLike("%" + keyword + "%");
		}
		List<CourierVo> courierVos = courierVoMapper
				.selectByExample(courierVoExample);
		return courierVos;
	}

	private List<OrderStatisticalVo> paginator(List<OrderStatisticalVo> list,
			int pageCount, int pageSize)
	{
		List<OrderStatisticalVo> newList = new ArrayList<OrderStatisticalVo>();
		for (int i = ((pageCount - 1) * pageSize); i < Math.min(list.size(),
				(pageCount * pageSize)); i++)
		{
			newList.add(list.get(i));
		}
		return newList;
	}

	/**
	 * 两张表id有可能不同,所以通过adminName找另一张表中某个admin的id
	 * 
	 * @param adminId
	 * @return
	 */
	private int getIdfromInfomationToLogin(int adminId)
	{
		String adminName = adminInfomationMapper.selectByPrimaryKey(adminId)
				.getAdminName();
		AdminLoginExample adminLoginExample = new AdminLoginExample();
		adminLoginExample.or().andAdminNameEqualTo(adminName);
		return adminLoginMapper.selectByExample(adminLoginExample).get(0)
				.getAdminId();
	}

	@Override
	public List<AdminLogin> test(int pageCount, int pageSize)
	{
		AdminLoginExample adminLoginExample = new AdminLoginExample();

		adminLoginExample.setStartAndPageSize((pageCount - 1) * pageSize,
				pageSize);

		adminLoginExample.setOrderByClause("admin_name DESC");
		return adminLoginMapper.selectByExample(adminLoginExample);
	}

	private String checkString(String str)
	{
		return str == null ? "" : str;
	}

	@Override
	public OrderDetailInfomationVo getOrderDetailInfomationByOrderId(int orderId)
	{
		OrderDetailInfomationVo orderDetailInfomationVo = new OrderDetailInfomationVo();
		OrderDetailInfomationViewExample orderDetailInfomationViewExample = new OrderDetailInfomationViewExample();
		orderDetailInfomationViewExample.or().andOrderIdEqualTo(orderId);
		OrderDetailInfomationView orderDetailInfomationView = orderDetailInfomationViewMapper
				.selectByExample(orderDetailInfomationViewExample).get(0);
		int purchaseUserId = orderDetailInfomationView.getPurchaseUserId();
		UserInfomation userInfomation = userInfomationMapper
				.selectByPrimaryKey(purchaseUserId);
		orderDetailInfomationVo
				.setOrderDetailInfomationView(orderDetailInfomationView);
		orderDetailInfomationVo.setPurchaseUserheadPortraitUrl(userInfomation
				.getHeadPortraitUrl());
		orderDetailInfomationVo.setPurchaseUserNickname(userInfomation
				.getNickname());
		return orderDetailInfomationVo;
	}

	@Override
	public List<Integer> getUsersNumberByDay(int day)
	{
		List<Integer> result = new ArrayList<Integer>();
		// 取得当天0点
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		calendar.set(Calendar.MILLISECOND, 0);
		// 将时间设置为第二天0点
		calendar.add(Calendar.DATE, 1);
		UserInfomationExample userInfomationExample;
		for (int i = 0; i < day; i++)
		{
			userInfomationExample = new UserInfomationExample();
			userInfomationExample.or().andUserRegisterTimeLessThan(
					calendar.getTime());
			int count = userInfomationMapper
					.countByExample(userInfomationExample);
			result.add(count);
			calendar.add(Calendar.DATE, -1);
		}

		return result;
	}

	@Override
	public List<Integer> getActivityUsersNumberByDay(int day)
	{
		List<Integer> result = new ArrayList<Integer>();
		// 取得当天0点
		Calendar calendarEarly = Calendar.getInstance();
		calendarEarly.set(Calendar.HOUR_OF_DAY, 0);
		calendarEarly.set(Calendar.MINUTE, 0);
		calendarEarly.set(Calendar.SECOND, 0);
		calendarEarly.set(Calendar.MILLISECOND, 0);
		// 取得第二天0点
		Calendar calendarLater = calendarEarly;
		calendarLater.add(Calendar.DATE, 1);
		UserInfomationExample userInfomationExample = new UserInfomationExample();
		for (int i = 0; i <= day; i++)
		{
			userInfomationExample
					.or()
					.andUserRegisterTimeGreaterThanOrEqualTo(
							calendarEarly.getTime())
					.andUserRegisterTimeLessThan(calendarLater.getTime());
			int count = userInfomationMapper
					.countByExample(userInfomationExample);
			result.add(count);
			calendarEarly.add(Calendar.DATE, -1);
			calendarLater.add(Calendar.DATE, -1);
		}

		return result;
	}

	@Override
	/**
	 * 1.取得请求订单数量
	 * 2.取得代购订单数量
	 * 3.取得所有订单数量
	 */
	public int selectCount(int switchCase, int userId, String key, int sequence)
	{
		UserOrderViewExample userOrderViewExample;
		Criteria criteria;
		switch (switchCase)
		{
		case 1:
			userOrderViewExample = new UserOrderViewExample();
			criteria = userOrderViewExample.or();
			if (key != null && key.length() > 0)
			{
				criteria.andNicknameLike("%" + key + "%");
			}
			criteria.andUserIdEqualTo(userId);
			return userOrderViewMapper.countByExample(userOrderViewExample);
		case 2:
			userOrderViewExample = new UserOrderViewExample();
			criteria = userOrderViewExample.or();
			if (key != null && key.length() > 0)
			{
				criteria.andNicknameLike("%" + key + "%");
			}
			userOrderViewExample.or().andPurchaseUserIdEqualTo(userId);
			return userOrderViewMapper.countByExample(userOrderViewExample);
		case 3:
			return selectCount(1, userId, key, sequence)
					+ selectCount(2, userId, key, sequence);

		case 4:
			userOrderViewExample = new UserOrderViewExample();
			criteria = userOrderViewExample.or();
			if (key != null && key.length() > 0)
			{
				criteria.andNicknameLike("%" + key + "%");
			}
			return userOrderViewMapper.countByExample(userOrderViewExample);
		case 5:
			AdminVoExample adminVoExample = new AdminVoExample();
			cn.edu.zjgsu.ito.model.AdminVoExample.Criteria criteriaAdmin = adminVoExample
					.or();
			adminVoExample.setOrderByClause("admin_name");
			criteriaAdmin.andAdminNameLike("%" + key == null ? "" : key + "%");
			switch (sequence)
			{
			case 1:
				break;
			case 2:
				criteriaAdmin.andAdminPowerEqualTo(1);
				break;
			case 3:
				criteriaAdmin.andAdminPowerEqualTo(0);
				break;
			default:
				break;
			}
			return adminVoMapper.countByExample(adminVoExample);
		case 6:
			UserVoExample userVoExample = new UserVoExample();
			if (key != null && key.length() > 0)
			{
				userVoExample.or().andUsernameLike("%" + key + "%");
			}
			return userVoMapper.countByExample(userVoExample);
		case 7:
			CourierVoExample courierVoExample = new CourierVoExample();
			cn.edu.zjgsu.ito.model.CourierVoExample.Criteria criteriaCourier = courierVoExample
					.or();
			if (key != null && key.length() > 0)
			{
				criteriaCourier.andUsernameLike("%" + key + "%");
			}
			return courierVoMapper.countByExample(courierVoExample);
		default:
			break;
		}
		return 0;
	}

	public int selectCount(String keyword, int sequence, int courierId)
	{

		UserOrderViewExample userOrderViewExample = new UserOrderViewExample();
		Criteria criteria = userOrderViewExample.or();
		if (keyword != null && keyword.length() > 0)
		{
			criteria.andNicknameLike("%" + keyword + "%");
		}
		criteria.andCourierIdEqualTo(courierId);
		return userOrderViewMapper.countByExample(userOrderViewExample);

	}

	@Override
	public int closeAccount(int userId)
	{
		UserLogin userLogin = userLoginMapper.selectByPrimaryKey(userId);
		userLogin.setUserState(0);
		return userLoginMapper.updateByPrimaryKeySelective(userLogin);
	}

	/*
	 * @Override public int closeOrderByOrderId(int orderId) { OrderTable
	 * orderTable = orderTableMapper.selectByPrimaryKey(orderId);
	 * orderTable.setOrderState(2); int resultCount =
	 * orderTableMapper.updateByPrimaryKeySelective(orderTable);
	 * if(resultCount!=1) { throw new RuntimeException("关闭订单时出错"); } return
	 * resultCount; }
	 * 
	 * @Override public int openOrderByOrderId(int orderId) { // TODO
	 * Auto-generated method stub return 0; }
	 */

	@Override
	public int changeOrderStateByOrderId(int orderId, int state)
	{
		OrderTable orderTable = orderTableMapper.selectByPrimaryKey(orderId);
		orderTable.setOrderState(state);
		int resultCount = orderTableMapper
				.updateByPrimaryKeySelective(orderTable);
		if (resultCount != 1)
		{
			throw new RuntimeException("关闭订单时出错");
		}
		return resultCount;
	}

	@Override
	public void deductUserIntegralScore(int userId, int integralScore)
	{
		UserScore userScore = userScoreMapper.selectByPrimaryKey(userId);
		userScore.setIntegralScore(Math.max(0, userScore.getIntegralScore()
				- integralScore));

		int resultCount = userScoreMapper
				.updateByPrimaryKeySelective(userScore);
		if (resultCount != 1)
		{
			throw new RuntimeException("扣除信誉分时出错");
		}

	}

	@Override
	public void changeCourierState(int courierId, int state)
	{
		UserCourier userCourier = userCourierMapper
				.selectByPrimaryKey(courierId);
		userCourier.setUserCourierState(state);
		int resultCount = userCourierMapper
				.updateByPrimaryKeySelective(userCourier);
		if (resultCount != 1)
		{
			throw new RuntimeException("审核时错误");
		}
	}

	@Override
	public Page<ComplainView> getComplainByPaging(int state, int pageCount,
			int pageSize)
	{
		Page<ComplainView> page = new Page<ComplainView>();
		ComplainViewExample complainViewExample = new ComplainViewExample();
		complainViewExample.setStart(Math.max(0, (pageCount - 1) * pageSize));
		complainViewExample.setPageSize(pageSize);
		complainViewExample.setOrderByClause("complain_time DESC");
		switch (state)
		{
		case 0:
			break;
		case 1:
			complainViewExample.or().andComplainStateEqualTo(0);
			break;
		case 2:
			complainViewExample.or().andComplainStateEqualTo(1);
			break;
		default:
			break;
		}
		List<ComplainView> complainViews = complainViewMapper
				.selectByExample(complainViewExample);
		page.setData(complainViews);
		page.setPageCount(pageCount);
		page.setPageSize(pageSize);
		page.setTotalCount(complainViewMapper
				.countByExample(complainViewExample));
		return page;
	}

	@Override
	public OrderDetailInfomationView getOrderDetailInfomationView(int orderId)
	{
		OrderDetailInfomationViewExample orderDetailInfomationViewExample = new OrderDetailInfomationViewExample();
		orderDetailInfomationViewExample.or().andOrderIdEqualTo(orderId);
		List<OrderDetailInfomationView> orderDetailInfomationViews = orderDetailInfomationViewMapper
				.selectByExample(orderDetailInfomationViewExample);
		if (orderDetailInfomationViews.size() != 1)
			return null;
		else
			return orderDetailInfomationViews.get(0);
	}

	@Override
	public void completeComplain(int complainId)
	{
		Complain complain = complainMapper.selectByPrimaryKey(complainId);
		complain.setId(1);
		int resultCount = complainMapper.updateByPrimaryKeySelective(complain);
		if (resultCount != 1)
		{
			throw new RuntimeException("完成投诉流程时出错");
		}

	}

	@Override
	public void changeAccountState(int userId, int state)
	{
		UserLogin userLogin = userLoginMapper.selectByPrimaryKey(userId);
		userLogin.setUserState(state);
		int resultCount = userLoginMapper
				.updateByPrimaryKeySelective(userLogin);
		if (resultCount != 1)
		{
			throw new RuntimeException();
		}
	}

	@Override
	public ComplainView getComplainById(int complainId)
	{
		ComplainViewExample complainViewExample = new ComplainViewExample();
		complainViewExample.or().andIdEqualTo(complainId);
		List<ComplainView> comList = complainViewMapper
				.selectByExample(complainViewExample);
		if (comList.size() != 1)
		{
			throw new RuntimeException();
		}
		return comList.get(0);
	}

	@Override
	public List<UserVo> getUsers(int sequence)
	{
		UserVoExample userVoExample = new UserVoExample();
		switch (sequence)
		{
		case 1:
			// 最新排前面
			userVoExample.setOrderByClause("last_login_time DESC");
			break;
		case 2:
			userVoExample.setOrderByClause("last_login_time");
			break;
		case 3:
			// 最新排前面
			userVoExample.setOrderByClause("credit_score");
			break;
		case 4:
			userVoExample.setOrderByClause("credit_score DESC");
			break;
		case 5:
			// 最新排前面
			userVoExample.setOrderByClause("user_register_time");
			break;
		case 6:
			userVoExample.setOrderByClause("user_register_time DESC");
			break;
		default:
			break;
		}
		return userVoMapper.selectByExample(userVoExample);
	}

	@Override
	public List<AdminVo> getAdmins(int sequence)
	{
		AdminVoExample adminVoExample = new AdminVoExample();
		switch (sequence)
		{
		case 1:
			break;
		case 2:
			adminVoExample.or().andAdminPowerEqualTo(1);
			break;
		case 3:
			adminVoExample.or().andAdminPowerEqualTo(0);
			break;
		case 4:
			adminVoExample.setOrderByClause("admin_createtime");
			break;
		case 5:
			adminVoExample.setOrderByClause("admin_createtime DESC");
			break;
		default:
			break;
		}
		return adminVoMapper.selectByExample(adminVoExample);
	}

	@Override
	public List<OrderDetailInfomationView> getAllOrderByCourierId(
			int courierId, int sequence)
	{
		OrderDetailInfomationViewExample orderDetailInfomationViewExample = new OrderDetailInfomationViewExample();
		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria = orderDetailInfomationViewExample
				.or();
		criteria.andCourierUserIdEqualTo(courierId);
		List<Integer> states = new ArrayList<Integer>()
		{
			{
				add(6);
				add(9);
			}
		};
		switch (sequence)
		{
		case 1:
			criteria.andOrderStateIn(states);
			break;
		case 2:
			criteria.andOrderStateNotIn(states);
			break;
		case 3:
			orderDetailInfomationViewExample.setOrderByClause("arrive_time");
			break;
		case 4:
			orderDetailInfomationViewExample
					.setOrderByClause("arrive_time DESC");
			break;
		case 5:
			orderDetailInfomationViewExample
					.setOrderByClause("demand_createtime");
			break;
		case 6:
			orderDetailInfomationViewExample
					.setOrderByClause("demand_createtime DESC");
			break;
		default:
			break;
		}
		return orderDetailInfomationViewMapper
				.selectByExample(orderDetailInfomationViewExample);
	}

	@Override
	public List<CourierVo> getCouriers(int sequence)
	{
		CourierVoExample courierVoExample = new CourierVoExample();
		switch (sequence)
		{
		case 1:
			courierVoExample.setOrderByClause("sum_order");
			break;
		case 2:
			courierVoExample.setOrderByClause("sum_order DESC");
			break;
		case 3:
			courierVoExample.setOrderByClause("score");
			break;
		case 4:
			courierVoExample.setOrderByClause("score DESC");
			break;
		case 5:
			courierVoExample.setOrderByClause("create_time DESC");
			break;
		case 6:
			courierVoExample.setOrderByClause("create_time");
			break;
		default:
			break;
		}
		return courierVoMapper.selectByExample(courierVoExample);
	}

	@Override
	public List<OrderDetailInfomationView> getDemandOrderByUserId(int userId,
			int sequence, int selectType, java.util.Date beginTime,
			java.util.Date endTime)
	{
		OrderDetailInfomationViewExample orderDetailInfomationViewExample = new OrderDetailInfomationViewExample();

		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria = orderDetailInfomationViewExample
				.or();
		criteria.andUserIdEqualTo(userId);

		/**
		 * 订单状态 0-等待代购人确定金额 1-确认，未支付 2-已支付 3-找快递员 4-待取件 5-派送中 6-完成 7-关闭 8-退款中
		 */
		if (String.valueOf(selectType) != null)
		{
			switch (selectType)
			{
			case 1:
				criteria.andDemandCreatetimeBetween(beginTime, endTime);
				break;
			case 2:
				criteria.andArriveTimeBetween(beginTime, endTime);
				break;
			default:
				break;
			}
		}

		if (sequence != -1)
		{
			criteria.andOrderStateEqualTo(sequence);
		}

		List<OrderDetailInfomationView> orderDetailInfomationViews = orderDetailInfomationViewMapper
				.selectByExample(orderDetailInfomationViewExample);
		for (int i = 0; i < orderDetailInfomationViews.size(); i++)
		{
			orderDetailInfomationViews.get(i).setType(1);
		}
		return orderDetailInfomationViews;
	}

	@Override
	public List<OrderDetailInfomationView> getPurcaseOrderByUserId(int userId,
			int sequence, int selectType, java.util.Date beginTime,
			java.util.Date endTime)
	{
		OrderDetailInfomationViewExample orderDetailInfomationViewExample = new OrderDetailInfomationViewExample();

		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria = orderDetailInfomationViewExample
				.or();
		criteria.andPurchaseUserIdEqualTo(userId);
		/**
		 * 订单状态 0-等待代购人确定金额 1-确认，未支付 2-已支付 3-找快递员 4-待取件 5-派送中 6-完成 7-关闭 8-退款中
		 */
		if (String.valueOf(selectType) != null)
		{
			switch (selectType)
			{
			case 1:
				criteria.andDemandCreatetimeBetween(beginTime, endTime);
				break;
			case 2:
				criteria.andArriveTimeBetween(beginTime, endTime);
				break;
			default:
				break;
			}
		}

		if (sequence != -1)
		{
			criteria.andOrderStateEqualTo(sequence);
		}
		/*
		 * List<Integer> states = new ArrayList<Integer>() { { add(6); add(9); }
		 * }; switch (sequence) { case 1: criteria.andOrderStateIn(states);
		 * break; case 2: criteria.andOrderStateNotIn(states); break; case 3:
		 * orderDetailInfomationViewExample.setOrderByClause("arrive_time");
		 * break; case 4: orderDetailInfomationViewExample
		 * .setOrderByClause("arrive_time DESC"); break; case 5:
		 * orderDetailInfomationViewExample
		 * .setOrderByClause("demand_createtime"); break; case 6:
		 * orderDetailInfomationViewExample
		 * .setOrderByClause("demand_createtime DESC"); break;
		 * 
		 * default: break; }
		 */

		List<OrderDetailInfomationView> orderDetailInfomationViews = orderDetailInfomationViewMapper
				.selectByExample(orderDetailInfomationViewExample);
		for (int i = 0; i < orderDetailInfomationViews.size(); i++)
		{
			orderDetailInfomationViews.get(i).setType(2);
		}
		return orderDetailInfomationViews;
	}

	@Override
	public List<OrderDetailInfomationView> getAllOrderByUserId(int userId,
			int sequence, int selectType, java.util.Date beginTime,
			java.util.Date endTime)
	{
		OrderDetailInfomationViewExample orderDetailInfomationViewExample = new OrderDetailInfomationViewExample();

		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria = orderDetailInfomationViewExample
				.or();
		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria2 = orderDetailInfomationViewExample
				.or();
		criteria.andPurchaseUserIdEqualTo(userId);
		criteria2.andUserIdEqualTo(userId);
		/**
		 * 订单状态 0-等待代购人确定金额 1-确认，未支付 2-已支付 3-找快递员 4-待取件 5-派送中 6-完成 7-关闭 8-退款中
		 */
		if (String.valueOf(selectType) != null)
		{
			switch (selectType)
			{
			case 1:
				criteria.andDemandCreatetimeBetween(beginTime, endTime);
				criteria2.andDemandCreatetimeBetween(beginTime, endTime);
				break;
			case 2:
				criteria.andArriveTimeBetween(beginTime, endTime);
				criteria2.andArriveTimeBetween(beginTime, endTime);
				break;
			default:
				break;
			}
		}

		List<Integer> stateComplete = new ArrayList<Integer>()
		{
			{
				add(6);
				add(9);
			}
		};
		switch (sequence)
		{
		case 1:
			criteria.andOrderStateIn(stateComplete);
			criteria2.andOrderStateIn(stateComplete);
			break;
		case 2:
			criteria.andOrderStateNotIn(stateComplete);
			criteria2.andOrderStateNotIn(stateComplete);
			break;
		case 3:
			orderDetailInfomationViewExample.setOrderByClause("arrive_time");
			break;
		case 4:
			orderDetailInfomationViewExample
					.setOrderByClause("arrive_time DESC");
			break;
		case 5:
			orderDetailInfomationViewExample
					.setOrderByClause("demand_createtime");
			break;
		case 6:
			orderDetailInfomationViewExample
					.setOrderByClause("demand_createtime DESC");
			break;
		default:
			break;
		}

		List<OrderDetailInfomationView> orderDetailInfomationViews = orderDetailInfomationViewMapper
				.selectByExample(orderDetailInfomationViewExample);
		for (int i = 0; i < orderDetailInfomationViews.size(); i++)
		{
			orderDetailInfomationViews.get(i).setType(
					orderDetailInfomationViews.get(i).getUserId() == userId ? 1
							: 2);
		}
		return orderDetailInfomationViews;
	}

	@Override
	public List<OrderDetailInfomationView> getAllOrders(int sequence,
			int selectType, java.util.Date beginTime, java.util.Date endTime)
	{
		OrderDetailInfomationViewExample orderDetailInfomationViewExample = new OrderDetailInfomationViewExample();

		cn.edu.zjgsu.ito.model.OrderDetailInfomationViewExample.Criteria criteria = orderDetailInfomationViewExample
				.or();
		/**
		 * 订单状态 0-等待代购人确定金额 1-确认，未支付 2-已支付 3-找快递员 4-待取件 5-派送中 6-完成 7-关闭 8-退款中
		 */
		if (String.valueOf(selectType) != null)
		{
			switch (selectType)
			{
			case 1:
				criteria.andDemandCreatetimeBetween(beginTime, endTime);
				break;
			case 2:
				criteria.andArriveTimeBetween(beginTime, endTime);
				break;
			default:
				break;
			}
		}

		if (sequence != -1)
		{
			criteria.andOrderStateEqualTo(sequence);
		}

		List<OrderDetailInfomationView> orderDetailInfomationViews = orderDetailInfomationViewMapper
				.selectByExample(orderDetailInfomationViewExample);
		return orderDetailInfomationViews;
	}

	@Override
	public List<ComplainView> getComplainByPaging(int state)
	{
		ComplainViewExample complainViewExample = new ComplainViewExample();
		complainViewExample.setOrderByClause("complain_time DESC");
		switch (state)
		{
		case 0:
			break;
		case 1:
			complainViewExample.or().andComplainStateEqualTo(0);
			break;
		case 2:
			complainViewExample.or().andComplainStateEqualTo(1);
			break;
		default:
			break;
		}
		List<ComplainView> complainViews = complainViewMapper
				.selectByExample(complainViewExample);
		return complainViews;
	}

	@Override
	public Integer selectOrderCountByState(int state)
	{
		OrderTableExample orderTableExample = new OrderTableExample();
		orderTableExample.or().andOrderStateEqualTo(state);
		return orderTableMapper.countByExample(orderTableExample);
	}

	@Override
	public int selectMoney(List<Integer> states)
	{
		int money = 0;
		// orderDetailInfomationViewMapper.selectSumMoney(states);
		return money;
	}

	@Override
	public List<CourierVo> getCouriersApproval(int sequence)
	{
		CourierVoExample courierVoExample = new CourierVoExample();
		List<Integer> states = new ArrayList<Integer>()
		{
			{
				add(2);
				add(4);
			}
		};
		courierVoExample.or().andUserCourierStateIn(states);

		if (String.valueOf(sequence) != null)
		{
			switch (sequence)
			{
			case 1:
				courierVoExample.setOrderByClause("last_login_time");
				break;
			case 2:
				courierVoExample.setOrderByClause("last_login_time DESC");
				break;
			case 3:
				courierVoExample.setOrderByClause("credit_score");
				break;
			case 4:
				courierVoExample.setOrderByClause("credit_score DESC");
				break;
			case 5:
				courierVoExample.setOrderByClause("user_register_time");
				break;
			case 6:
				courierVoExample.setOrderByClause("user_register_time DESC");
				break;
			default:
				break;
			}
		}

		return courierVoMapper.selectByExample(courierVoExample);
	}

	@Override
	public int getTotalAdminCount()
	{
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public List<CapitalVo> getMoney(int sequenceInt)
	{
		List<Integer> states = new ArrayList<Integer>()
		{
			{
				add(2);
				add(3);
				add(4);
				add(5);
				add(6);
				add(8);
				add(9);
			}
		};
		OrderDetailInfomationViewExample orderDetailInfomationViewExample = new OrderDetailInfomationViewExample();
		orderDetailInfomationViewExample.or().andOrderStateIn(states);
		List<OrderDetailInfomationView> orders = orderDetailInfomationViewMapper
				.selectByExample(orderDetailInfomationViewExample);

		List<CapitalVo> capitalVos = new ArrayList<CapitalVo>();
		CapitalVo capitalVo;
		OrderDetailInfomationView order;
		for (int i = 0; i < orders.size(); i++)
		{

			order = orders.get(i);
			if (sequenceInt != 2)
			{
				capitalVo = new CapitalVo();
				BeanUtils.copyProperties(order, capitalVo);
				capitalVo.setType(1);
				capitalVo.setMoneyDirection(1);
				capitalVo.setTime(order.getDemandCreatetime());
				capitalVo.setMoney(order.getEstimateThePrice() == null ? 0
						: Integer.valueOf(order.getEstimateThePrice()));
				capitalVos.add(capitalVo);

				capitalVo = new CapitalVo();
				capitalVo.setUserId(order.getPurchaseUserId());
				capitalVo.setHeadPortraitUrl(order
						.getPurchaseUserheadPortraitUrl());
				capitalVo.setNickname(order.getPurchaseUserNickname());
				capitalVo.setType(2);
				capitalVo.setMoneyDirection(2);
				capitalVo.setMoney(order.getCourierFees() == null ? 0 : Integer
						.valueOf(order.getCourierFees()));
				capitalVo.setTime(order.getAcceptTime());
				capitalVos.add(capitalVo);
			}

			if (sequenceInt != 1)
			{
				if (order.getOrderState() == 6 || order.getOrderState() == 9)
				{
					capitalVo = new CapitalVo();
					BeanUtils.copyProperties(order, capitalVo);
					capitalVo.setType(3);
					capitalVo.setMoneyDirection(3);
					capitalVo.setTime(order.getDemandCreatetime());
					capitalVo.setMoney(order.getEstimateThePrice() == null ? 0
							: Integer.valueOf(order.getEstimateThePrice()));
					capitalVos.add(capitalVo);

					capitalVo = new CapitalVo();
					capitalVo.setUserId(order.getPurchaseUserId());
					capitalVo.setHeadPortraitUrl(order
							.getPurchaseUserheadPortraitUrl());
					capitalVo.setNickname(order.getPurchaseUserNickname());
					capitalVo.setType(4);
					capitalVo.setMoneyDirection(4);
					capitalVo.setMoney(order.getCourierFees() == null ? 0
							: Integer.valueOf(order.getCourierFees()));
					capitalVo.setTime(order.getAcceptTime());
					capitalVos.add(capitalVo);
				}
			}

		}

		switch (sequenceInt)
		{
		case 3:
			Collections.sort(capitalVos, new Comparator<CapitalVo>()
			{

				@Override
				public int compare(CapitalVo capitalVo1, CapitalVo capitalVo2)
				{
					return capitalVo1.getMoney() > capitalVo2.getMoney() ? 1
							: capitalVo1.getMoney() == capitalVo2.getMoney() ? 0
									: -1;
				}
			});

			break;
		case 4:
			Collections.sort(capitalVos, new Comparator<CapitalVo>()
			{

				@Override
				public int compare(CapitalVo capitalVo1, CapitalVo capitalVo2)
				{
					return -(capitalVo1.getMoney() > capitalVo2.getMoney() ? 1
							: capitalVo1.getMoney() == capitalVo2.getMoney() ? 0
									: -1);
				}
			});

			break;
		case 5:
			Collections.sort(capitalVos, new Comparator<CapitalVo>()
			{

				@Override
				public int compare(CapitalVo capitalVo1, CapitalVo capitalVo2)
				{
					long time1 = capitalVo1.getTime()==null?0:capitalVo1.getTime().getTime();
					long time2 = capitalVo2.getTime()==null?0:capitalVo2.getTime().getTime();
					return time1 >time2? 1 :time1== time2 ? 0
							: -1;
				}
			});
			break;
		case 6:
			Collections.sort(capitalVos, new Comparator<CapitalVo>()
			{

				@Override
				public int compare(CapitalVo capitalVo1, CapitalVo capitalVo2)
				{
					long time1 = capitalVo1.getTime()==null?0:capitalVo1.getTime().getTime();
					long time2 = capitalVo2.getTime()==null?0:capitalVo2.getTime().getTime();
					return -(time1 >time2? 1 :time1== time2 ? 0
							: -1);
				}
			});
			break;
		default:
			break;
		}

		return capitalVos;
	}

	@Override
	public List<UserInfomation> selectTopUser(int number)
	{
		UserInfomationExample userInfomationExample = new UserInfomationExample();
		userInfomationExample.setOrderByClause("user_order_sum DESC");
		userInfomationExample.setStart(0);
		userInfomationExample.setPageSize(number);
		return userInfomationMapper.selectByExample(userInfomationExample);
	}

	@Override
	public List<CourierVo> selectTopCourier(int number)
	{
		CourierVoExample courierVoExample = new CourierVoExample();
		courierVoExample.setOrderByClause("sum_order DESC");
		courierVoExample.setStart(0);
		courierVoExample.setPageSize(number);
		return courierVoMapper.selectByExample(courierVoExample);
	}

	@Override
	public int test()
	{
		// 订单状态 0-等待代购人确定金额 1-确认，未支付 2-已支付 3-找快递员 4-待取件 5-派送中 6-完成未评价 7-关闭 8-退款中
		// 9-结束
		List<Integer> states = new ArrayList<Integer>()
		{
			{
				// add(2);
				// add(3);
				// add(4);
				// add(5);
				add(6);
				// add(8);
				add(9);
			}
		};
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		calendar.set(Calendar.MILLISECOND, 0);
		java.util.Date beginTime = calendar.getTime();
		calendar.add(Calendar.DATE, 1);
		java.util.Date endTime = calendar.getTime();
		String money = orderDetailInfomationViewMapper.getTotalMoneyOut(
				beginTime, endTime, states);

		return money == null ? 0 : Integer.valueOf(money);
	}

	@Override
	public int selectMoneyIn(Date beginTime, Date endTime, List<Integer> states)
	{
		String money = orderDetailInfomationViewMapper.getTotalMoneyIn(
				beginTime, endTime, states);
		return money == null ? 0 : Integer.valueOf(money);
	}

	@Override
	public int selectMoneyOut(Date beginTime, Date endTime, List<Integer> states)
	{
		String money = orderDetailInfomationViewMapper.getTotalMoneyOut(
				beginTime, endTime, states);
		return money == null ? 0 : Integer.valueOf(money);
	}

}
